//
//  KeyboardEmoticonCell.swift
//  Emoji
//
//  Created by 钟清 on 17/4/11.
//  Copyright © 2017年 Zhong Qing. All rights reserved.
//

import UIKit

class KeyboardEmoticonCell: UICollectionViewCell {
    /* 对应cell的表情模型 */
    var emoticon: KeyboardEmoticons? {
        didSet {
            /* 显示emoji表情，其由String直接获得 */
            iconButton.setTitle(emoticon?.emoticonStr, forState: UIControlState.Normal)
            /* 显示图片表情 */
            iconButton.setImage(nil, forState: UIControlState.Normal) // 使用前先清空，避免cell的重用
            if emoticon?.chs != nil {
                iconButton.setImage( UIImage(contentsOfFile: emoticon!.pngPath!), forState: UIControlState.Normal)
            }
            /* 添加删除按钮 */
            if emoticon!.isRemoveButton { // 标记为真
                iconButton.setImage(UIImage(named: "compose_emotion_delete"), forState: UIControlState.Normal)
                iconButton.setImage(UIImage(named: "compose_emotion_delete_highlighted"), forState: UIControlState.Highlighted)
                
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
    
    // MARK: - 内部控制方法
    private func setupUI() {
        contentView.addSubview(iconButton)
        iconButton.backgroundColor = UIColor.whiteColor()
        iconButton.frame = CGRectInset(bounds, 4, 4)
        
    }
    // MARK: - Lazy
    private lazy var iconButton: UIButton = {
        let btn = UIButton()
        btn.userInteractionEnabled = false
        btn.titleLabel?.font = UIFont.systemFontOfSize(30)
        return btn
    }()
}
